package com.xjh.basestudy.javabase.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author:XuJianHua
 * @Date:2022/11/16
 * @Description: 从任意一个传入的对象中获取数据
 */
public class test {

  public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
    Student student = new Student();
    student.setId(2);

    getParam(student);

  }

  public static void getParam(Object object) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Class clazz = object.getClass();
    String subjectClass = clazz.getSimpleName();
    Method method = clazz.getMethod("getId", new Class[]{});
    String id = method.invoke(object, new Object[]{}).toString();
    System.out.println(id);
  }

}
